export class ResponsePackage {
    public static to(result) {
        return result.flag ? ResponsePackage.toResponse(result.output) : ResponsePackage.toErrorResponse(result.output);
    }

    public static toResponse(data) {
        return {
            data,
            message: 'Success',
            status: HTTP_STATUSCODE.GET_OR_PUT,
        };
    }

    public static toErrorResponse(message) {
        return {
            data: [],
            message,
            status: HTTP_STATUSCODE.INTERNAL_SERVER_ERROR,
        };
    }
}

export const HTTP_STATUSCODE = {
    GET_OR_PUT: '200',
    POST: '201',
    RECEIVED: '202',
    // tslint:disable-next-line: object-literal-sort-keys
    DELETE: '204',
    NOT_MODIFIED: '304',
    BAD_REQUEST: '400',
    UNAUTHORIZED: '401',
    FORBIDDEN: '403',
    NOT_FOUNDED: '404',
    INTERNAL_SERVER_ERROR: '500',
    NOT_IMPLEMENTED: '501',
};
